<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
            width: 300px;
        }
    </style>
</head>

<body>
    <img src="https://img2.baidu.com/it/u=3015045708,4243438371&fm=26&fmt=auto&gp=0.jpg" alt="">
    <div>上午好</div>
    <script>
        // 1. 获取元素
        var img = document.querySelector('img');
        var div = document.querySelector('div');
        // 2. 得到当前的小时数
        var date = new Date();
        var h = date.getHours();
        // 3. 判断时间改变图片和文字
        if (h < 12) {
            img.src = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic25.nipic.com%2F20121123%2F8703155_142824282150_2.jpg&refer=http%3A%2F%2Fpic25.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633921834&t=90a8ae104cb59f7f073aa6808faa111c';
            div.innerHTML = '上午好 好好学习';
        } else if (h < 18) {
            img.src = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic33.nipic.com%2F20130924%2F12085979_105431188100_2.jpg&refer=http%3A%2F%2Fpic33.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633921834&t=2f04063fca7795638b4f24f0fee962c3';
            div.innerHTML = '下午好 好好学习';
        } else {
            img.src = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic18.nipic.com%2F20120202%2F7919931_150439721000_2.jpg&refer=http%3A%2F%2Fpic18.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633921834&t=05f65876be80e14a7dac45bf8d6f6ce0';
            div.innerHTML = '晚上好 好好学习';
        }
    </script>
</body>

</html>